
/*
 * Copyright 2008 Friendster Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
*/

using System;
using System.Collections;
using System.Text;

namespace Friendster.Service
{
    /// <summary>
    /// Represents the user data class
    /// </summary>
    public sealed class User : FriendsterEntity
    {
        // Methods
        private BirthDay birthDay;
        private MemberSince memberSince;
        private LocaTion locaTion;
        public CollegeList Colleges;
        public SchoolList Schools;
        private InterestedIn interestedIn;
        private Favorites favorites;
        /// <summary>
        /// Initializes the object for use, including session initialization.
        /// </summary>
        /// <param name="userState"></param>
        internal User(Hashtable userState):base((Hashtable)userState["user"])
        {
            userState = (Hashtable)userState["user"];
            try
            {
                birthDay = new BirthDay((Hashtable)userState["birthday"]);
            }
            catch
            {
                birthDay = null;
            }
            try
            {
                memberSince = new MemberSince((Hashtable)userState["member_since"]);
            }
            catch
            {
                memberSince = null;
            }
            try
            {
                locaTion = new LocaTion((Hashtable)userState["location"]);
            }
            catch
            {
                locaTion = null;
            }
            try
            {
                Colleges = new CollegeList((ArrayList)userState["college_list"]);
            }
            catch
            {
                Colleges = null;
            }
            try
            {
                Schools = new SchoolList((ArrayList)userState["school_list"]);
            }
            catch
            {
                Schools = null;
            }
            try
            {
                interestedIn = new InterestedIn((ArrayList)userState["interested_in"]);
            }
            catch
            {
                interestedIn = null;
            }
            try
            {
                favorites = new Favorites((Hashtable)userState["favorites"]);
            }
            catch
            {
                favorites = null;
            }
        }

        /// <summary>
        /// Returns user ID
        /// </summary>
        public string ID
        {
            get
            {
                return base.GetState<string>("uid") ?? string.Empty;
            }
        }
        /// <summary>
        /// Returns First name of user. 
        /// </summary>
        public string FirstName
        {
            get
            {
                return (base.GetState<string>("first_name") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the last name of user.
        /// </summary>
        public string LastName
        {
            get
            {
                return (base.GetState<string>("last_name") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the fullname of user.
        /// </summary>
        public string FullName
        {
            get
            {
                return (base.GetState<string>("full_name") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the concatenation of firstname and last name of user. 
        /// </summary>
        public string Name
        {
            get
            {
                return ( FirstName +" "+ LastName ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the user gender.
        /// </summary>
        public string Gender
        {
            get
            {
                return (base.GetState<string>("gender") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the user's entity type.
        /// </summary>
        public string EntityType
        {
            get
            {
                return (base.GetState<string>("entity_type") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the user's entity category.
        /// </summary>
        public string EntityCategory 
        {
            get
            {
                return (base.GetState<string>("entity_category") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the Membersince object.
        /// </summary>
        public MemberSince Membersince
        {

            get
            {
                return (memberSince ?? null);
            }
        }
        /// <summary>
        /// Returns the relationship status of user.
        /// </summary>
        public string Relationship
        {
            get
            {
                return (base.GetState<string>("relationship_status") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the string array of user's inetersts in relationships.
        /// </summary>
        public string[] InterestedInRelationships
        {
            get
            {
                return interestedIn.Intestes;
            }
        }
        /// <summary>
        /// Returns user's Birthday object.
        /// </summary>
        public BirthDay Birthday
        {
            get
            {
                return (birthDay ?? null);
            }
        }
        /// <summary>
        /// Returns the Location object for current user.
        /// </summary>
        public LocaTion Location
        {
            get
            {
                return (locaTion ?? null);
            }
        }
        /// <summary>
        /// Returns the hometown of current user.
        /// </summary>
        public string Hometown
        {
            get
            {
                return (base.GetState<string>("hometown") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the occupation of user.
        /// </summary>
        public string Occupation
        {
            get
            {
                return (base.GetState<string>("occupation") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the company information of user.
        /// </summary>
        public string Companies
        {
            get
            {
                return (base.GetState<string>("companies") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns user's hobbies and interests.
        /// </summary>
        public string Interests
        {
            get
            {
                string interests = (base.GetState<string>("hobbies_and_interests") ?? string.Empty);
                return interests.Trim();
            }
        }
        /// <summary>
        /// Returns user's affiliations.
        /// </summary>
        public string Affiliations
        {
            get
            {
                return (base.GetState<string>("affiliations") ?? string.Empty);
            }
        }

        // College property
        public sealed class CollegeList
        {
            private ArrayList collegeState = new ArrayList();
            public int NumberOfColleges;
            
            internal CollegeList(ArrayList collegeState)
            {
                this.collegeState = collegeState;
                this.NumberOfColleges = collegeState.Count;
            }
            public College this[int Index]
            {
                get
                {
                    return new College((Hashtable)this.collegeState[Index]);
                }
            }
        }
        // End College proparty.

        // School proparty
        public sealed class SchoolList
        {
            private ArrayList schoolState = new ArrayList();
            public int NumberOfSchools;
            internal SchoolList(ArrayList schoolState)
            {
                this.schoolState = schoolState;
                this.NumberOfSchools = schoolState.Count;
            }
            public School this[int Index]
            {
                get
                {
                    return new School((Hashtable)this.schoolState[Index]);
                }
            }
        }
        // End School proparty.

        // Fevorites proparties
        /// <summary>
        /// Returns the favorite musics of user.
        /// </summary>
        public string Music
        {
            get
            {
                return (favorites.Musics ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the favorite movies of user.
        /// </summary>
        public string Movies
        {
            get
            {
                return (favorites.Movie ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the favorite TV shows of user.
        /// </summary>
        public string TVShows
        {
            get
            {
                return (favorites.TvShows ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the favorite books of user.
        /// </summary>
        public string Books
        {
            get
            {
                return (favorites.Book ?? string.Empty);
            }
        }

        // End of Favorites proparties
        /// <summary>
        /// Returns the About Me information of user.
        /// </summary>
        public string About
        {
            get
            {
                string aboutMe=(base.GetState<string>("about_me") ?? string.Empty);
                return aboutMe.Trim();
            }
        }
        /// <summary>
        /// Returns the wish of user, to whome (s)he wants to meet.
        /// </summary>
        public string WantToMeet
        {
            get
            {
                string wantToMeet = (base.GetState<string>("want_to_meet") ?? string.Empty);
                return wantToMeet.Trim();
            }
        }
    }
}
